{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 1. Image Functions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Table of Contents\n", "* [1. Image Functions](#1.-Image-Functions)\n", "\t* [1.1 Using Images in your Code](#1.1-Using-Images-in-your-Code)\n", "\t* [1.2 Pixel-based Drawing](#1.2-Pixel-based-Drawing)\n", "\t* [1.3 Image Flipping](#1.3-Image-Flipping)\n", "\t\t* [1.3.1 Horizontal Mirror](#1.3.1-Horizontal-Mirror)\n", "\t* [1.4 Blue Screen, er Pink Screen](#1.4-Blue-Screen,-er-Pink-Screen)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.1 Using Images in your Code" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is an easy way to make your creations look better.\n", "\n", "1. get an image into your folder\n", " * upload a picture\n", " * use %download\n", "2. include the name in a special comment in your sketch\n", "3. use loadImage()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "%download http://www.spongebobvitamins.com/images/spongBob.png" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "\n", " var component = document.getElementById(\"sketch_3\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"state_3\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"controls_div_3\");\n", " if (component != undefined)\n", " component.remove();\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " // FIXME: Stop all previously running versions (?)\n", " var processingInstance = Processing.getInstanceById(\"canvas_3\");\n", " if (processingInstance != undefined && processingInstance.isRunning())\n", " processingInstance.noLoop();\n", " });\n", "\n", "\n", " var output_area = this;\n", " // find my cell element\n", " var cell_element = output_area.element.parents('.cell');\n", " // which cell is it?\n", " var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);\n", " // get the cell object\n", " var cell = Jupyter.notebook.get_cell(cell_idx);\n", "\n", " function jyp_print(cell, newline) {\n", " return function(message) {\n", " cell.get_callbacks().iopub.output({header: {\"msg_type\": \"stream\"},\n", " content: {text: message + newline,\n", " name: \"stdout\"}});\n", " }\n", " }\n", " window.jyp_println = jyp_print(cell, \"\\n\");\n", " window.jyp_print = jyp_print(cell, \"\");\n", "\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " Processing.logger.println = jyp_print(cell, \"\\n\");\n", " Processing.logger.print = jyp_print(cell, \"\");\n", " });\n", "\n", "\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " Sketch #3:
\n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", "
\n", "Sketch #3 state: Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "/* @pjs preload=\"spongBob.png\"; */\n", "\n", "PImage img;\n", "\n", "void setup() {\n", " img = loadImage(\"spongBob.png\");\n", " size(img.width, img.height);\n", "}\n", "\n", "void draw() {\n", " background(0, 128, 0);\n", " image(img, 0, 0);\n", " noLoop();\n", "}" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "\n", " var component = document.getElementById(\"sketch_4\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"state_4\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"controls_div_4\");\n", " if (component != undefined)\n", " component.remove();\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " // FIXME: Stop all previously running versions (?)\n", " var processingInstance = Processing.getInstanceById(\"canvas_4\");\n", " if (processingInstance != undefined && processingInstance.isRunning())\n", " processingInstance.noLoop();\n", " });\n", "\n", "\n", " var output_area = this;\n", " // find my cell element\n", " var cell_element = output_area.element.parents('.cell');\n", " // which cell is it?\n", " var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);\n", " // get the cell object\n", " var cell = Jupyter.notebook.get_cell(cell_idx);\n", "\n", " function jyp_print(cell, newline) {\n", " return function(message) {\n", " cell.get_callbacks().iopub.output({header: {\"msg_type\": \"stream\"},\n", " content: {text: message + newline,\n", " name: \"stdout\"}});\n", " }\n", " }\n", " window.jyp_println = jyp_print(cell, \"\\n\");\n", " window.jyp_print = jyp_print(cell, \"\");\n", "\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " Processing.logger.println = jyp_print(cell, \"\\n\");\n", " Processing.logger.print = jyp_print(cell, \"\");\n", " });\n", "\n", "\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " Sketch #4:
\n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", "
\n", "Sketch #4 state: Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "/* @pjs preload=\"spongBob.png\"; */\n", "// added comment\n", "\n", "float g = 9.8; \n", "\n", "float vx;\n", "float vy;\n", "\n", "float x;\n", "float y;\n", "\n", "float dt; \n", "float t;\n", "\n", "PImage img; // added global\n", "\n", "void setup() {\n", " img = loadImage(\"spongBob.png\"); // added loadImage\n", " size(200, 500);\n", " x = width/2;\n", " y = 50;\n", " dt = 0.1; \n", " t = 0;\n", " vx = 5.0;\n", " vy = 0.0;\n", "}\n", "\n", "void drawBall(float x, float y, float scale) {\n", " //fill(255, 0, 0);\n", " //ellipse(x, y, 10 * scale, 10 * scale);\n", " image(img, x - 15, y - 15, 30, 30); // added\n", "}\n", "\n", "void draw() {\n", " background(0, 0, 128);\n", " // gravity\n", " vy = vy + g * dt;\n", " \n", " float dx = vx * dt; \n", " if (((x + dx) > width) || ((x + dx) < 0)) {\n", " vx = vx * -1;\n", " } else {\n", " x = x + dx;\n", " }\n", " \n", " float dy = vy * dt;\n", " if (((y + dy) > height) || ((y + dy) < 0)) {\n", " vy = vy * -1;\n", " } else {\n", " y = y + dy;\n", " }\n", "\n", " drawBall(x, y, 1);\n", " \n", " t = t + dt;\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.2 Pixel-based Drawing" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, let's draw an image that we create:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "\n", " var component = document.getElementById(\"sketch_5\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"state_5\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"controls_div_5\");\n", " if (component != undefined)\n", " component.remove();\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " // FIXME: Stop all previously running versions (?)\n", " var processingInstance = Processing.getInstanceById(\"canvas_5\");\n", " if (processingInstance != undefined && processingInstance.isRunning())\n", " processingInstance.noLoop();\n", " });\n", "\n", "\n", " var output_area = this;\n", " // find my cell element\n", " var cell_element = output_area.element.parents('.cell');\n", " // which cell is it?\n", " var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);\n", " // get the cell object\n", " var cell = Jupyter.notebook.get_cell(cell_idx);\n", "\n", " function jyp_print(cell, newline) {\n", " return function(message) {\n", " cell.get_callbacks().iopub.output({header: {\"msg_type\": \"stream\"},\n", " content: {text: message + newline,\n", " name: \"stdout\"}});\n", " }\n", " }\n", " window.jyp_println = jyp_print(cell, \"\\n\");\n", " window.jyp_print = jyp_print(cell, \"\");\n", "\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " Processing.logger.println = jyp_print(cell, \"\\n\");\n", " Processing.logger.print = jyp_print(cell, \"\");\n", " });\n", "\n", "\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " Sketch #5:
\n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", "
\n", "Sketch #5 state: Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "PImage img;\n", "\n", "void setup() {\n", " size(500, 500);\n", " img = new PImage(200, 300, RGB);\n", "}\n", "\n", "void draw() {\n", " background(128);\n", " image(img, 0, 0);\n", " noLoop();\n", "}\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We know that we can create shapes using the built-in Processing functions like rect(). But what are they doing at the deepest level? Could we do it ourselves?" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "PImage img;\n", "\n", "void setup() {\n", " size(500, 500);\n", " img = new PImage(500, 500, RGB);\n", "}\n", "\n", "void draw() {\n", " myrect(10, 20, 200, 200, color(255, 0, 0));\n", " mycircle(300, 300, 75, color(0, 255, 0));\n", " image(img, 0, 0);\n", " noLoop();\n", "}\n", "\n", "void myrect(int x, int y, int w, int h, color c) {\n", " img.loadPixels();\n", " // what would go here?\n", " img.updatePixels();\n", "}\n", "\n", "void mycircle(int x, int y, int radius, color c) {\n", " img.loadPixels();\n", " // what would go here?\n", " img.updatePixels();\n", "}\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Yes, we could. All we need to do is change the pixels ourselves, like this:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "\n", " var component = document.getElementById(\"sketch_6\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"state_6\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"controls_div_6\");\n", " if (component != undefined)\n", " component.remove();\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " // FIXME: Stop all previously running versions (?)\n", " var processingInstance = Processing.getInstanceById(\"canvas_6\");\n", " if (processingInstance != undefined && processingInstance.isRunning())\n", " processingInstance.noLoop();\n", " });\n", "\n", "\n", " var output_area = this;\n", " // find my cell element\n", " var cell_element = output_area.element.parents('.cell');\n", " // which cell is it?\n", " var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);\n", " // get the cell object\n", " var cell = Jupyter.notebook.get_cell(cell_idx);\n", "\n", " function jyp_print(cell, newline) {\n", " return function(message) {\n", " cell.get_callbacks().iopub.output({header: {\"msg_type\": \"stream\"},\n", " content: {text: message + newline,\n", " name: \"stdout\"}});\n", " }\n", " }\n", " window.jyp_println = jyp_print(cell, \"\\n\");\n", " window.jyp_print = jyp_print(cell, \"\");\n", "\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " Processing.logger.println = jyp_print(cell, \"\\n\");\n", " Processing.logger.print = jyp_print(cell, \"\");\n", " });\n", "\n", "\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " Sketch #6:
\n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", "
\n", "Sketch #6 state: Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "PImage img;\n", "\n", "void setup() {\n", " size(500, 500);\n", " img = new PImage(500, 500, RGB);\n", "}\n", "\n", "void draw() {\n", " myrect(10, 20, 200, 200, color(255, 0, 0));\n", " mycircle(300, 300, 75, color(0, 255, 0));\n", " image(img, 0, 0);\n", " noLoop();\n", "}\n", "\n", "void myrect(int x, int y, int w, int h, color c) {\n", " img.loadPixels();\n", " // what would go here?\n", " for (int i=x; i < x + w; i++) {\n", " for (int j=y; j < y + h; j++) {\n", " img.pixels[i + j * img.width] = c;\n", " }\n", " }\n", " img.updatePixels();\n", "}\n", "\n", "void mycircle(int x, int y, int radius, color c) {\n", " img.loadPixels();\n", " // what would go here?\n", " for (int i=x-radius; i < x + radius; i++) {\n", " for (int j=y-radius; j < y + radius; j++) {\n", " if (dist(x, y, i, j) < radius) {\n", " img.pixels[i + j * img.width] = c;\n", " }\n", " }\n", " }\n", " img.updatePixels();\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**BONUS PROBLEM 1:**\n", "\n", "Try to draw a line, like:\n", "\n", "```java\n", "void myline(float x1, float y1, float x2, float y2) {\n", " // handle vertical line\n", " // handle horizontal line\n", " // handle the other cases\n", "}\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.3 Image Flipping" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1.3.1 Horizontal Mirror" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For this demonstration, I'll use this picture of a student:\n", "\n", "\n", "\n", "You can download it, and upload it yourself, or use:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "%download https://jupyter.brynmawr.edu/services/public/dblank/CS110%20Intro%20to%20Computing/2017-Fall/Notebooks/IMG_4688.jpeg" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, let's just test it and display it:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "\n", " var component = document.getElementById(\"sketch_8\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"state_8\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"controls_div_8\");\n", " if (component != undefined)\n", " component.remove();\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " // FIXME: Stop all previously running versions (?)\n", " var processingInstance = Processing.getInstanceById(\"canvas_8\");\n", " if (processingInstance != undefined && processingInstance.isRunning())\n", " processingInstance.noLoop();\n", " });\n", "\n", "\n", " var output_area = this;\n", " // find my cell element\n", " var cell_element = output_area.element.parents('.cell');\n", " // which cell is it?\n", " var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);\n", " // get the cell object\n", " var cell = Jupyter.notebook.get_cell(cell_idx);\n", "\n", " function jyp_print(cell, newline) {\n", " return function(message) {\n", " cell.get_callbacks().iopub.output({header: {\"msg_type\": \"stream\"},\n", " content: {text: message + newline,\n", " name: \"stdout\"}});\n", " }\n", " }\n", " window.jyp_println = jyp_print(cell, \"\\n\");\n", " window.jyp_print = jyp_print(cell, \"\");\n", "\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " Processing.logger.println = jyp_print(cell, \"\\n\");\n", " Processing.logger.print = jyp_print(cell, \"\");\n", " });\n", "\n", "\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " Sketch #8:
\n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", "
\n", "Sketch #8 state: Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "/* @pjs preload=\"IMG_4688.jpeg\"; */\n", "\n", "PImage img;\n", "\n", "void setup() {\n", " img = loadImage(\"IMG_4688.jpeg\");\n", " img.resize(int(img.width/20), int(img.height/20));\n", " size(img.width, img.height);\n", "}\n", "\n", "void draw() {\n", " image(img, 0, 0);\n", " noLoop();\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, let's flip it so that everything on the right is on the left and everything on the left is on the right.\n", "\n", "To do that, we just map the pixels so that the pixels in the first column (zero) will now be in the last column (img.width - 1):" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "\n", " var component = document.getElementById(\"sketch_9\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"state_9\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"controls_div_9\");\n", " if (component != undefined)\n", " component.remove();\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " // FIXME: Stop all previously running versions (?)\n", " var processingInstance = Processing.getInstanceById(\"canvas_9\");\n", " if (processingInstance != undefined && processingInstance.isRunning())\n", " processingInstance.noLoop();\n", " });\n", "\n", "\n", " var output_area = this;\n", " // find my cell element\n", " var cell_element = output_area.element.parents('.cell');\n", " // which cell is it?\n", " var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);\n", " // get the cell object\n", " var cell = Jupyter.notebook.get_cell(cell_idx);\n", "\n", " function jyp_print(cell, newline) {\n", " return function(message) {\n", " cell.get_callbacks().iopub.output({header: {\"msg_type\": \"stream\"},\n", " content: {text: message + newline,\n", " name: \"stdout\"}});\n", " }\n", " }\n", " window.jyp_println = jyp_print(cell, \"\\n\");\n", " window.jyp_print = jyp_print(cell, \"\");\n", "\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " Processing.logger.println = jyp_print(cell, \"\\n\");\n", " Processing.logger.print = jyp_print(cell, \"\");\n", " });\n", "\n", "\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " Sketch #9:
\n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", "
\n", "Sketch #9 state: Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "/* @pjs preload=\"IMG_4688.jpeg\"; */\n", "\n", "PImage img;\n", "PImage result;\n", "\n", "void setup() {\n", " img = loadImage(\"IMG_4688.jpeg\");\n", " img.resize(int(img.width/5), int(img.height/5));\n", " size(img.width, img.height);\n", " img.loadPixels(); \n", " // Create a result from img:\n", " result = new PImage(img.width, img.height);\n", " result.loadPixels();\n", " for (int y=0; y < img.height; y++) {\n", " for (int x=0; x < img.width; x++) {\n", " color c = img.pixels[x + y * img.width];\n", " result.pixels[img.width - 1 - x + (y * img.width)] = c;\n", " }\n", " } \n", " result.updatePixels();\n", "}\n", "\n", "void draw() {\n", " image(result, 0, 0);\n", " noLoop();\n", "}\n" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "**BONUS PROBLEM 2:**\n", "\n", "Flip student upside down. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.4 Blue Screen, er Pink Screen" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "\n", " var component = document.getElementById(\"sketch_11\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"state_11\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"controls_div_11\");\n", " if (component != undefined)\n", " component.remove();\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " // FIXME: Stop all previously running versions (?)\n", " var processingInstance = Processing.getInstanceById(\"canvas_11\");\n", " if (processingInstance != undefined && processingInstance.isRunning())\n", " processingInstance.noLoop();\n", " });\n", "\n", "\n", " var output_area = this;\n", " // find my cell element\n", " var cell_element = output_area.element.parents('.cell');\n", " // which cell is it?\n", " var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);\n", " // get the cell object\n", " var cell = Jupyter.notebook.get_cell(cell_idx);\n", "\n", " function jyp_print(cell, newline) {\n", " return function(message) {\n", " cell.get_callbacks().iopub.output({header: {\"msg_type\": \"stream\"},\n", " content: {text: message + newline,\n", " name: \"stdout\"}});\n", " }\n", " }\n", " window.jyp_println = jyp_print(cell, \"\\n\");\n", " window.jyp_print = jyp_print(cell, \"\");\n", "\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " Processing.logger.println = jyp_print(cell, \"\\n\");\n", " Processing.logger.print = jyp_print(cell, \"\");\n", " });\n", "\n", "\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " Sketch #11:
\n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", "
\n", "Sketch #11 state: Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "/* @pjs preload=\"IMG_4688.jpeg\"; */\n", "\n", "PImage img;\n", "\n", "void setup() {\n", " img = loadImage(\"IMG_4688.jpeg\");\n", " img.resize(int(img.width/5), int(img.height/5));\n", " size(img.width, img.height);\n", " img.loadPixels();\n", " for (int y=0; y < img.height; y++) {\n", " for (int x=0; x < img.width; x++) {\n", " color c = img.pixels[x + y * img.width];\n", " float r = red(c);\n", " float g = green(c);\n", " float b = blue(c);\n", " // 201, 59, 98\n", " if ((190 < r && r < 250 &&\n", " 55 < g && g < 90 &&\n", " 90 < b && b < 150)) { // ||\n", " //...\n", " img.pixels[x + (y * img.width)] = color(0, 255, 0);\n", " }\n", " }\n", " } \n", " img.updatePixels(); \n", "}\n", "\n", "void mousePressed() {\n", " color c = img.get(mouseX, mouseY);\n", " float r = red(c);\n", " float g = green(c);\n", " float b = blue(c);\n", " println(\"RGB: \" + r + \", \" + g + \", \" + b);\n", "}\n", "\n", "void draw() {\n", " image(img, 0, 0);\n", " noLoop();\n", "}" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "**BONUS PROBLEM 3:**\n", "\n", "Make as much as the pink area turn green without anything else turning green." ] } ], "metadata": { "kernelspec": { "display_name": "Calysto Processing", "language": "java", "name": "calysto_processing" }, "language_info": { "codemirror_mode": { "name": "text/x-java", "version": 2 }, "file_extension": ".java", "mimetype": "text/x-java", "name": "java" } }, "nbformat": 4, "nbformat_minor": 1 }